<?php

namespace backend\assets;

use yii\web\AssetBundle;

/**
 * Main backend application asset bundle.
 */
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';

    public $css = [
        ['css/main.css'],
        'css/part2.css',
        'css/style.css',
        ['css/ie.css', 'condition' => 'lte IE9'],
    ];

    public $js = [
        ['js/extra.js', 'position' => \yii\web\View::POS_HEAD],
        'js/elements.js',
        'js/base.js',
    ];

    public $depends = [
        'yii\web\YiiAsset',
        'common\assets\JqueryFormAsset',
        'common\assets\JqueryValidateAsset',
        'common\assets\BootstrapAsset',
        'common\assets\FontAwesomeAsset',
        'common\assets\LayerAsset',
    ];

    public static function register($view)
    {
        !empty($view->params['css_plguins']) && self::addStyles($view, $view->params['css_plguins']);
        !empty($view->params['js_plugins']) && self::addScripts($view, $view->params['js_plugins']);
        return parent::register($view);
    }

    public static function addScripts($view, $files)
    {
        foreach ($files as $k => $v) {
            $view->registerJsFile($v, ['depends' => 'backend\assets\PluginAsset']);
        }
    }

    public static function addStyles($view, $files)
    {
        foreach ($files as $k => $v) {
            $view->registerCssFile($v, ['depends' => 'backend\assets\PluginAsset']);
        }
    }

    public static function registerPageJsFile($view, $file)
    {
        $view->registerJsFile('/js/pages/' . $file . '.js', ['depends' => 'backend\assets\AppAsset']);
    }
}
